<?php

namespace App\Http\Controllers\Frontend;


use App\Logics\AccountLogic;
use App\Logics\CaptchaLogic;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Redirect;


class AccountController extends BaseController
{
    // 用户账户
    public function initialize()
    {
        parent::initialize();
    }

    // 登录
    public function login()
    {
        $logic = new AccountLogic();
        $res   = $logic->login();
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    // 注册
    public function reg()
    {
        $logic = new AccountLogic();
        $res   = $logic->reg();
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    // 忘记密码
    public function forget()
    {
        $logic = new AccountLogic();
        $res   = $logic->forget();
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    // 发送验证码
    public function sendEmail()
    {
        $logic = new AccountLogic();
        $res   = $logic->sendEmail();
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    // 修改密码
    public function password()
    {
        if(empty($this->myUser)){
            return $this->error('please_login_before_operation');
        }

        $logic = new AccountLogic();
        $res   = $logic->password($this->myUser);
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    //  查询测试
    // http://www.shop.com/account/captcha/click
    public function click()
    {
        $logic = new CaptchaLogic();
        $res   = $logic->clickCaptcha();

        return $this->success($res);
    }

    /**
     * 点选验证码检查：验证
     */
    public function checkClick()
    {
        $logic = new CaptchaLogic();
        $res   = $logic->checkClickCaptcha();
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success();
    }

}


